from flask import Flask, render_template
from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm
from wtforms import SubmitField, PasswordField, EmailField
from wtforms.validators import DataRequired, Email, Length
app = Flask(__name__)
app.secret_key = "any-string-you-want-just-keep-it-secret"
Bootstrap(app)

class Credendials():
    EMAIL = 'sasha@admin.com'
    PASSWORD = 'password'

def is_match_credentials(email: str, password: str) -> bool:
    if email == Credendials.EMAIL and password == Credendials.PASSWORD:
        return True
    return False

class MyForm(FlaskForm):
    email = EmailField('Email', validators=[DataRequired(), Email()])
    password = PasswordField('Password', validators=[DataRequired(), Length(8)])
    submit = SubmitField(label='Send')


@app.route("/")
def home():
    return render_template('index.html')
  
@app.route("/login", methods=["GET", "POST"])
def login():
    login_form = MyForm()
    is_valid = login_form.validate_on_submit()
    if is_valid:
        if is_match_credentials(login_form.email.data, login_form.password.data):
            return render_template('success.html')
        else:
            return render_template('denied.html')
    return render_template('login.html', form=login_form)
  
if __name__ == '__main__':
    app.run(debug=True)
